package com.ruoyi.business.controller.item;

import com.ruoyi.base.controller.BaseController;
import com.ruoyi.base.enums.item.PlanetaryMaterialsEnum;
import com.ruoyi.base.exception.CustomException;
import com.ruoyi.base.factory.ItemFactory;
import com.ruoyi.base.pojo.HttpResult;
import com.ruoyi.business.pojo.item.ItemDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 项目
 * @author Administrator
 */
@Api(tags = "项目")
@RestController
@RequestMapping("/item")
public class ItemController extends BaseController {
    /**
     * 获取项目列表
     */
    @ApiOperation("获取项目列表")
    @GetMapping("/list")
    public HttpResult<List<ItemDTO>> getTypeList(int type) {
        return data(ItemFactory.getByCode(type));
    }

    /**
     * 获取完美行星所在地
     */
    @ApiOperation("获取完美行星所在地")
    @GetMapping("/perfect")
    public HttpResult<List<String>> getPerfect(int code) {
        return data(Arrays.stream(Optional.ofNullable(PlanetaryMaterialsEnum.ofCode(code)).orElseThrow(() -> new CustomException("未查询到结果")).getMaxPlant()).collect(Collectors.toList()));
    }
}
